//logs.js
const util = require('../../utils/util.js')
// 在页面中定义激励视频广告


// 在页面中定义插屏广告
let interstitialAd = null

Page({
  data: {
    keyword:'',
    logs: []
  },


  onLoad: function (options) {

    console.log("keyword : " + options.keyword) 
    this.onrequest(options.keyword)


// 在页面onLoad回调事件中创建插屏广告实例
if (wx.createInterstitialAd) {
  interstitialAd = wx.createInterstitialAd({
    adUnitId: 'adunit-af67eed49c2713e6'
  })
  interstitialAd.onLoad(() => {})
  interstitialAd.onError((err) => {})
  interstitialAd.onClose(() => {})
}
  
  },

  onShow(){

    // 在适合的场景显示插屏广告
if (interstitialAd) {
  interstitialAd.show().catch((err) => {
    console.error(err)
  })
}
  },

  onCopy(){

    let that = this;
    wx.setClipboardData({
      //准备复制的数据
       data: that.data.logs[0],
       success: function (res) {
         wx.showToast({
           title: '复制成功',
         });
       }
     });

  },

  onrequest(res){

    let that = this

    wx.showNavigationBarLoading({
      success: (res) => {},
    })
    wx.request({
      url: 'https://cts.market.alicloudapi.com/cts', //仅为示例，并非真实的接口地址
      data: {
        key: res,
        num: '7',
        type:'1',
        yayuntype:'1'
      },
      header: {
        'Authorization':'APPCODE f38b9a82f7ae48078e85d651be45f46f',
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data)
        
        wx.hideNavigationBarLoading({
          success: (res) => {},
        })
        
        if(res.data.showapi_res_body.ret_code == -1){


          let list = []

          list.push(res.data.showapi_res_body.remark)
          
         
          that.setData({

            logs : list
  
          })

          wx.showToast({
            title: res.data.showapi_res_body.remark
          })

        }else{

          that.setData({

            logs : res.data.showapi_res_body.list
  
          })
        }
      
      }
    })
  }
})
